// app.js
App({
  onLaunch: function() {
    // 加载题库
    const that = this;
    try {
      // 导入题库数据模块
      const questions = require('./questions.js');
      console.log('题库数据加载成功:', questions);
      that.globalData.questions = questions;
      // 检查数据结构是否完整
      if (!questions.single_choice_one || !questions.single_choice_two || !questions.multiple_choice) {
        console.error('题库数据结构不完整');
      }
      wx.setStorage({
        key: 'examQuestions',
        data: questions
      });
    } catch (e) {
      console.error('加载题库模块失败:', e.message);
      console.error('错误堆栈:', e.stack);
      // 尝试从本地存储获取
      wx.getStorage({
        key: 'examQuestions',
        success(res) {
          console.log('从本地存储获取题库成功');
          that.globalData.questions = res.data;
        },
        fail() {
          console.error('从本地存储获取题库失败');
        }
      });
    }
  },
  globalData: {
    questions: null,
    examQuestions: null,
    userAnswers: {},
    startTime: 0,
    duration: 20 * 60 * 1000, // 20分钟
    isExamStarted: false
  }
})